﻿namespace Leetcode.N0547;
public class Solution
{
    public int FindCircleNum(int[][] isConnected)
    {
        bool[] visited = new bool[isConnected.Length];
        var num = 0;
        var queue = new System.Collections.Generic.Queue<int>();
        for (var i = 0; i < visited.Length; i++)
        {
            if (visited[i])
            {
                continue;
            }
            num++;
            visited[i] = true;
            queue.Enqueue(i);
            while (queue.Count > 0)
            {
                var item = queue.Dequeue();
                for (var j = 0; j < isConnected[item].Length; j++)
                {
                    if (visited[j] || isConnected[item][j] == 0)
                    {
                        continue;
                    }
                    visited[j] = true;
                    queue.Enqueue(j);
                }
            }

        }
        return num;
    }
}
